var flgChk_History=false;
$(function(){
	$('.Search_Results_History').hover(function() {

        $(this).addClass('onhover');

      }, function() {

        $(this).removeClass('onhover');

      });

    $('.Search_Results_History').click(function() {
 if (flgChk_History==false)
                {
            if (this.getElementsByTagName('INPUT')[0].checked==false)
                {
                    this.getElementsByTagName('INPUT')[0].checked=true;
                }
            else
            {
                this.getElementsByTagName('INPUT')[0].checked=false;
            }

           setFilter_History(2);
                }
                 else
            {
                flgChk_History=false;
            }
        });


	});



$(document).ready(function()
		{
			$("#selectAllresult_History").click(function()
			{
                                var para="";
                                var paraoverlay="";
                                var paranonspecies="";
                                var v=document.getElementsByName("selectResult_History");
                                  for (i=0;i<v.length;i++)
                                    {
                                        v[i].checked=true;
                            if (v[i].id=="selectResult_History_species_" + v[i].value)
                                {
                                        if (para!="")
						{
							para=para+","
						}
				para= para + v[i].value;

                                }
                             if (v[i].id=="selectResult_History_overlay_" + v[i].value)
                                {
                                        if (paraoverlay!="")
						{
							paraoverlay=paraoverlay+","
						}
				paraoverlay= paraoverlay + v[i].value;

                                }
                            if (v[i].id=="selectResult_History_nonspecies_" + v[i].value)
                                {
                                        if (paranonspecies!="")
						{
							paranonspecies=paranonspecies+","
						}
				paranonspecies= paranonspecies + v[i].value;

                                }
                                    }

                                setFilter_History("1",para+"OLY"+paraoverlay+"OLY"+paranonspecies);
			});
		});



$(document).ready(function()
		{
			$("#unselectAllresult_History").click(function()
			{

                                var v=document.getElementsByName("selectResult_History");
                                for (i=0;i<v.length;i++)
                                    {
                                        v[i].checked=false;
                                    }


                                setFilter_History("1","");
			});
		});


$(document).ready(function()
		{
			$("#clear_History").click(function()
			{
                            if (confirm("Do you want to clear History?")) {

                            window.sessionStorage.clear();
                            $("#history").html('<img src="/images/loading/loading9.gif">');
//                            alert(sessionStorage.getItem('history'));

                             $.post("http://"+location.hostname+"/searchresult/History", {searchhistory: sessionStorage.getItem('history')}, function(data) {
                                $("#history").html(data);
                                });
                            }
			});
		});


function setFilter_History(flg,pav,year_para_val,rtval)
{
chk=document.getElementsByName("selectResult_History");
var para="";
var paraoverlay="";
var paranonspecies="";
if (flg=="1")
    {

        var tm=pav.split("OLY", pav.length);
        if (tm[0]==undefined)
            para="";
        else
            para=tm[0];

        if (tm[1]==undefined)
            paraoverlay="";
        else
            paraoverlay=tm[1];

        if (tm[2]==undefined)
            paranonspecies="";
        else
            paranonspecies=tm[2];

    }
else if (flg=="2")
    {
for (var i=0; i < chk.length; i++)
	   {
			if (chk[i].checked==true && chk[i].id=="selectResult_History_species_" + chk[i].value)
			{
				if (para!="")
						{
							para=para+","
						}
				para= para + chk[i].value;
			}
                        if (chk[i].checked==true && chk[i].id=="selectResult_History_overlay_" + chk[i].value)
			{
				if (paraoverlay!="")
						{
							paraoverlay=paraoverlay+","
						}
				paraoverlay= paraoverlay + chk[i].value;

			}
                        if (chk[i].checked==true && chk[i].id=="selectResult_History_nonspecies_" + chk[i].value)
			{
				if (paranonspecies!="")
						{
							paranonspecies=paranonspecies+","
						}
				paranonspecies= paranonspecies + chk[i].value;

			}


		}
    }
    if (rtval!=undefined && rtval==true)
        {
            return para+"OLY"+paraoverlay;
        }
            LoadData(para+"OLY"+paraoverlay+"OLY"+paranonspecies);

            setOverlayImage(map,paraoverlay);
     if(para!=null && para!="" || (paranonspecies!=null && paranonspecies!=""))
         {loadMarker(map,para+"OLY"+paranonspecies);} else {loadMarker(map,"");}

   // Calls the Chart function on click of each checkbox from right panel
 if($("#reportarea").is(":visible")==true){DrawChart(para,year_para_val);}
}



function LoadData_History(selectedvalues)
{



                                 $("#citation").html('<img src="/images/loading/loading9.gif">');

				$.post("http://"+location.hostname+"/citation/Index", {search: selectedvalues}, function(data) {
                                $("#citation").html(data);
                                });
}


function showAttributeReportAllLocation_history()
{
    var para="";

       var v=$("span[name=searchLocationName_history]");

    for (i=0;i<v.length;i++)
        {

            if (para.search(v[i].innerHTML)==-1)
                {

            if (para!="")
                    {
                            para=para+","
                    }

    para= para + v[i].innerHTML;
                }
    }

    showattributereport(para);
}
$(function() {
		$("#unselectAllresult_History,#locationattributereportbtn_history,#selectAllresult_History,#downloadexceldata_History,#clear_History,#atrb").button();

	});